
 /**
  *数据的初始化
  * 数组的遍历
  */

public class Demo02 {
    public static void main(String[] args) {
        //定义整形数组并初始化
        int[] numbers = {11,22,66,23,56};
        System.out.println("numbers长度是：" + numbers.length);
        System.out.println("numbers第三个元素: " + numbers[2]);
        System.out.println("访问numbers所有的元素");
        //使用常规的for循环，遍历数组元素
        for (int i = 0; i < numbers.length; i++) {
            System.out.println(numbers[i]);
        }
        //定义字符数组并初始化
        String [] names = {"张飞","关羽","刘备","马超"};
        System.out.println("numbers的长度是: " + names.length);
        System.out.println("numbers最后一个元素:" + names[names.length - 1]);
        //常用for遍历names
        for (int i = 0; i < names.length; i++) {
            System.out.println("foreach循环数组: ");
            //foreach 通过变量依次变量每一个元素
            for (int num : numbers) {
                System.out.println("foreach退历number: " + num);
            }
            for (int num : numbers) {
                System.out.println("foreach退历number: " + num);
            }
        }

    }
}
